<?php
global $IP;
if( !defined( 'MEDIAWIKI' ) )
	die(-1);

require_once('DatabaseFunctions.php');

require_once("$IP/extensions/Tops/tops.php");

$wgExtensionCredits['specialpage'][] = array(
	'name' => 'TopAlbums',
	'author' => 'mp2p',
);


#install extension hook
$wgAjaxExportList[] = 'wfAjaxTopAlbums';
$wgExtensionFunctions[] = "wfSpecialPageTopAlbums";

function wfSpecialPageTopAlbums()
{
	SpecialPage::addPage( new TopAlbums() );
}

function wfAjaxTopAlbums($type, $page){
	return $page."#".renderTops($type, $page);
}


class TopAlbums extends SpecialPage
{
	function TopAlbums(){
		SpecialPage::SpecialPage("TopAlbums");
		return true;
		
	}

	function execute() {
       		global $wgOut, $wgRequest;
		$wgOut->setDefaultTitle('Top Albums');
		$wgOut->setPagetitle("Top Albums");
		$this->renderTopAlbums();
	}
	function renderTopAlbums() {
		global $wgScript, $wgRequest, $wgOut, $wgScriptPath;
		
		$wgOut->addScript("<script type=\"text/javascript\" src=\"/skins/soundshare/tops.js\"></script>\n");
		$wgOut->addHTML( '<div class="tops">');
		$wgOut->addHTML( '<input type="hidden" id="page" value="1">');
		$wgOut->addHTML('<div class="tops-popular">Popularity</div>');
		$output.="<div id='panel-topArtist1'></div>";
		$output .="</div>";
		$wgOut->addHTML($output);
		$this->createNextPageBar($page, 1000,$rowsByPage); 
		$output="<script>document.getElementById('page').value=1;moreAlbums()</script>";
		$wgOut->addHTML($output);
		
	
	}
 

	function createNextPageBar($page, $found, $rowsByPage) {
		global $wgOut,$wgRequest,$wgScript;
	
		$qry="javascript:moreAlbums()";
	
				
		$next_page = '<div style="text-align:center;margin-top:20px">';
		$next_page.= '<div class="button-grey"><div class="button-grey-start"></div>';
		$next_page .= '<a href="'.$qry;
		$next_page .= '">[+]' . wfMsg('sphinxNextPage') .'</a>';
		$next_page .= '<div class="button-grey-end"></div></div>';
		$next_page .='<img id="loader_tops"  src="/skins/soundshare/loader_tops.gif">';
		$next_page .= '<div style="padding-bottom:35px"></div></div> ';
		
		$wgOut->addHTML($next_page);
				
			
	}
	


	
	
}
